package com.syxp.pda.action.standard;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.syxp.pda.core.web.action.BaseAction;
import com.syxp.pda.entity.standard.BugLevel;
import com.syxp.pda.service.standard.BugLevelService;

public class BugLevelAction extends BaseAction {
	@Resource
	private BugLevelService bugLevelService;
	
	private int bugLevelID;
	private BugLevel bugLevel;
	
	public String load() {
		List list = new ArrayList(); 
		try {
			List<BugLevel> bugLevels = this.bugLevelService.getDao().getAll();
			for(BugLevel o: bugLevels) {
				Map map = new HashMap();
				map.put("bugLevelName", o.getBugLevelName());
				map.put("bugLevelID", o.getBugLevel());
				list.add(map);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
		this.jsonString = this.gson.toJson(list);
		System.out.println(this.jsonString);
		return SUCCESS;
	}
	
	public String save() {
		try {
			this.bugLevelService.addService(this.bugLevel);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}
	
	public String delete() {
		try {
			this.bugLevelService.removeService(this.bugLevelID);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}
	
	public String update() {
		try {
			this.bugLevelService.updateService(this.bugLevel);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}


	/**
	 * @return the bugLevelService
	 */
	public BugLevelService getBugLevelService() {
		return bugLevelService;
	}

	/**
	 * @param bugLevelService the bugLevelService to set
	 */
	public void setBugLevelService(BugLevelService bugLevelService) {
		this.bugLevelService = bugLevelService;
	}

	/**
	 * @return the bugLevelID
	 */
	public int getBugLevelID() {
		return bugLevelID;
	}

	/**
	 * @param bugLevelID the bugLevelID to set
	 */
	public void setBugLevelID(int bugLevelID) {
		this.bugLevelID = bugLevelID;
	}

	/**
	 * @return the bugLevel
	 */
	public BugLevel getBugLevel() {
		return bugLevel;
	}

	/**
	 * @param bugLevel the bugLevel to set
	 */
	public void setBugLevel(BugLevel bugLevel) {
		this.bugLevel = bugLevel;
	}
	

}
